
package at.fhooe.mcm12.java.serializer;

import java.util.HashMap;

import at.fhooe.mcm12.java.enums.OutputFormat;
import at.fhooe.mcm12.java.sensors.data.LightIntensity;
import at.fhooe.mcm12.java.utils.TimeUtils;

public class LightIntensitySerializer extends SensorSerializer<LightIntensity> {

	static final String PATH = "logs/light/light_log";
	private final String[] m_tags;

	public LightIntensitySerializer() {
		m_tags = new String[] { "timestamp", "intensity", "unit" };
		m_writers = new HashMap<>();
		m_writers.put(OutputFormat.XML, new XMLWriter());
		m_writers.put(OutputFormat.Text, new TextWriter());
		m_writers.put(OutputFormat.CSV, new CSVWriter());
	}

	@Override
	public void serialize(OutputFormat _format, LightIntensity _value) {
		String[] values = new String[] {
				TimeUtils.getCurrentTimeStamp(_value.getTimestamp()),
				String.format("%.2f", _value.getIntensity()),
				String.valueOf(_value.getUnit()) };
		m_writers.get(_format).log(PATH, m_tags, values);
	}

}
